package com.triones.api.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.NoticeMainContentDO;
import com.triones.api.entity.NoticeSceneDO;
import com.triones.api.entity.bo.NoticeBO;
import com.triones.api.entity.interlace.dto.InterlaceNoticeDO;
import com.triones.api.entity.interlace.dto.InterlaceNoticeSceneDO;
import com.triones.api.entity.interlace.vo.InterlaceNoticeSceneVO;
import com.triones.api.entity.param.CustomNoticeMemberParams;
import com.triones.api.entity.param.NoticeParams;
import com.triones.api.entity.vo.CustomNoticeMemberVO;
import com.triones.api.entity.vo.CustomNoticeVO;
import com.triones.api.entity.vo.NoticeMainContentVO;
import com.triones.api.entity.vo.NoticeSceneVO;
import com.triones.api.service.NoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通知
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/customNotice")
public class NoticeController extends BaseController {

    private final NoticeService noticeService;

    /**
     * 通知列表（分页）
     */
    @SaCheckPermission("system:interlaceNoticeList:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<CustomNoticeVO> pageList(InterlaceNoticeDO dto, PageQuery pageQuery) {
        return noticeService.pageList(dto, pageQuery);
    }

    /**
     * 删除通知
     */
    @SaCheckPermission("system:interlaceNoticeList:remove")
    @DeleteMapping("/{id}")
    public R<Void> remove(@PathVariable Long id) {
        return toAjax(noticeService.remove(id));
    }

    /**
     * 通知场景列表
     */
    @SaCheckPermission("system:interlaceNoticeScene:pageList")
    @GetMapping("/scene/pageList")
    public TableDataInfo<InterlaceNoticeSceneVO> noticeSceneList(String keyword, PageQuery pageQuery) {
        return noticeService.noticeSceneList(keyword, pageQuery);
    }

    /**
     * 通知场景新增
     */
    @SaCheckPermission("system:interlaceNoticeScene:add")
    @PostMapping("/scene")
    public R<Void> addNoticeScene(@Validated @RequestBody InterlaceNoticeSceneDO noticeSceneDO) {
        if (!noticeService.checkNoticeSceneName(noticeSceneDO)) {
            return R.fail("新增通知场景失败，场景名称或类型已存在");
        }
        return toAjax(noticeService.addNoticeScene(noticeSceneDO));
    }

    /**
     * 修改通知场景
     */
    @SaCheckPermission("system:interlaceNoticeScene:edit")
    @PutMapping("/scene")
    public R<Void> editNoticeScene(@Validated @RequestBody InterlaceNoticeSceneDO noticeSceneDO) {
        if (!noticeService.checkNoticeSceneName(noticeSceneDO)) {
            return R.fail("修改通知场景失败，场景名称或类型已存在");
        }
        return toAjax(noticeService.editNoticeScene(noticeSceneDO));
    }

    /**
     * 删除通知场景
     */
    @SaCheckPermission("system:interlaceNoticeScene:remove")
    @DeleteMapping("/scene/{id}")
    public R<Void> removeNoticeScene(@PathVariable Long id) {
        return toAjax(noticeService.removeNoticeScene(id));
    }

    /**
     * 获取通知场景详情
     */
    @SaCheckPermission("system:interlaceNoticeScene:query")
    @GetMapping("/scene/{id}")
    public R<InterlaceNoticeSceneVO> noticeSceneDetail(@PathVariable Long id) {
        return R.ok(noticeService.noticeSceneDetail(id));
    }

    /**
     * 通知场景列表
     */
    @GetMapping("/scene/list")
    public R<List<InterlaceNoticeSceneVO>> noticeSceneList() {
        return R.ok(noticeService.noticeSceneList());
    }

    /**
     * 通知新增
     */
    @SaCheckPermission("system:interlaceNoticeList:add")
    @PostMapping("/add")
    public R<Void> addNotice(@Validated @RequestBody NoticeBO bo) {
        noticeService.addNotice(bo);
        return R.ok();
    }

    /**
     * 通知用户列表（分页）
     */
    @GetMapping("/member/pageList")
    public TableDataInfo<CustomNoticeMemberVO> noticeMemberPageList(CustomNoticeMemberParams customNoticeMemberParams, PageQuery pageQuery) {
        return noticeService.noticeMemberPageList(customNoticeMemberParams, pageQuery);
    }
}
